package com.umxwe.kill.core.domain;

import java.util.HashMap;
import java.util.Map;

public class R extends HashMap<String, Object> {
    //
    private static final long serialVersionUID = -8157613083634272196L;

    private static final String MESSAGE = "message";
    private static final String DATA = "data";
    private static final String CODE = "code";
    private static final String SUCCESS = "success";

    public R() {
        put(CODE, 200);
        put(MESSAGE, SUCCESS);
    }

    public static R error() {
        return error(500, "未知异常，请联系管理员");
    }

    public static R error(String message) {
        return error(500, message);
    }

    public static R error(int code, String message) {
        R r = new R();
        r.put(CODE, code);
        r.put(MESSAGE, message);
        return r;
    }

    public static R ok(String message) {
        R r = new R();
        r.put(MESSAGE, message);
        return r;
    }

    public static R data(Object data) {
        R r = new R();
        r.put(DATA, data);
        return r;
    }

    public static R ok(Map<String, Object> map) {
        R r = new R();
        r.putAll(map);
        return r;
    }

    public static R ok() {
        return new R();
    }

    @Override
    public R put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}